'''
Created on Feb 1, 2012

@author: xzhu
'''

class MSTATE():
    '''
    one microstate of the free part of the protein
    '''

    def __init__(self, confs = []):
        '''
        Constructor
        '''
        
        self.conformers = confs
        self.self_ener   = 0.0
        self.inter_ener  = 0.0
        self.total_ener  = 0.0
        
        
    def __str__(self):
        '''
        print the conformer names of the microstate
        '''
        outStr = ''
        for conf in self.conformers:
            outStr += conf.confID + ' '

        return outStr
        
            
    def get_self_ener(self):
        '''
        get the self energy of these conformers
        '''
        for conf in self.conformers:
            self.self_ener += conf.selfEner
            if conf.confID[3:5] == 'DM': continue

            for sconf in self.conformers:
                if sconf.confID[3:5] == 'DM': continue
                if conf.iConf == sconf.iConf: continue
                else:
                    self.self_ener += conf.tPair[sconf.iConf] * 0.5
                    
    def display_self_ener(self):
        '''
        display all the energy terms composing the self.self_ener
        '''
        pass
        #print 'displaying the self energy term of the fixed part of the protein:'
        
        #for conf in self.conformers:
        #    print 'self ', conf.confID, 'conf.selfEner'
                            
    def inter_with_fix_prot(self, fixProt):
        '''
        interaction with the fixed residues in the protein
        '''
        
        for conf in self.conformers:
            if conf.confID[3:5] == 'DM': continue
            for sconf in fixProt.conformers:
                if sconf.confID[3:5] == 'DM': continue
                #print 'iConf: ' + str(sconf.iConf)
                self.inter_ener += conf.tPair[sconf.iConf] * sconf.focc
                
    def get_total_ener(self, prot):
        self.get_self_ener()
        self.inter_with_fix_prot(prot)

        self.total_ener = self.self_ener + self.inter_ener + prot.total_ener
        #print 'conf name ', self.conformers[0].confID, 'self ', self.self_ener, 'with fixed ', self.inter_ener, 'total ', self.total_ener
        
        
